package com.huaxin.controller;


import com.huaxin.model.User;
import com.huaxin.service.UserService;
import com.huaxin.utils.RestResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class UserController {


    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/user/userHello", method = RequestMethod.GET)
    public String hello() {
        System.out.println("111111111111111");
        return "hello";
    }

    @RequestMapping(value = "/user/userList", method = RequestMethod.GET)
    @ResponseBody
    public RestResult userList () {
        List<User> users=userService.userList();
        return RestResult.SUCCESS().put("users",users);
    }

    @RequestMapping(value = "/user/addUser", method = RequestMethod.POST)
    @ResponseBody
    public RestResult addUser () {
        userService.addUser();
        return RestResult.SUCCESS();
    }

    @RequestMapping(value = "/user/getUser", method = RequestMethod.GET)
    @ResponseBody
    public User getUser () {
        return userService.getUser(1);
    }


}
